{
	template:`
    <a-page-header>
        <template #title>
            <a-radio-group v-model:value="tabIndex" button-style="solid">
                <a-radio-button value="1">审核数据</a-radio-button>
                <a-radio-button value="2">审核结果</a-radio-button>
            </a-radio-group>
            <span class="padding-left">{{business.type}} <small>{{business.title}}</small></span>
        </template>
        <template #extra>
            <a-button v-if="instance.currentSection.saveable=='Y'" type="primary" ghost @click="saveFlow();">暂存</a-button>
            <block v-if="edit&&loadOver&&linkOptions&&linkOptions.length>0">
                <a-popconfirm v-if="selected.selectLink.isNext=='B'" title="确定要退回流程吗？" @confirm="processFlow();">
                    <a-button type="primary" danger>退回</a-button>
                </a-popconfirm>
                <a-popconfirm v-if="selected.selectLink.isNext=='Y'" title="确定要提交流程吗？" @confirm="processFlow();">
                    <a-button type="primary">提交</a-button>
                </a-popconfirm>
                <a-popconfirm v-if="selected.selectLink.isNext=='N'" title="确定要提交流程吗？" @confirm="processFlow();">
                    <a-button type="primary">完成</a-button>
                </a-popconfirm>
                <a-popconfirm v-if="selected.selectLink.forwardable=='Y'" title="确定要转发吗？" @confirm="processFlow();">
                    <a-button type="primary">转发</a-button>
                </a-popconfirm>
            </block>
            <m-back v-if="isOpen" @click="back(false);">关闭</m-back>
        </template>
    </a-page-header>
    <div v-if="!loadOver" class="padding">
        <a-skeleton active />
    </div>
    <div v-show="tabIndex=='1'">
        <div :id="'flowData'+key"></div>
    </div>
    <div v-show="tabIndex=='2'">
        <div style="padding:0 15px 15px;">
            <a-card :hoverable="true" :bodyStyle="{padding:'20px 20px 0'}">
                <a-form class="index-form" :wrapper-col="{span:24}">
                    <a-row :gutter="10">
                        <a-col :span="24">
                            <a-form-item label="流程" class="index-form-item">
                                {{define.name}} ( {{define.identity}} v{{define.version}})
                            </a-form-item>
                        </a-col>
                        <a-col v-if="instance.currentSection.oid" :span="24">
                            <a-form-item label="当前环节" class="index-form-item">
                                {{instance.currentSection.name}} ( {{instance.currentSection.identity}} )
                            </a-form-item>
                        </a-col>
                        <a-col v-if="!instance.oid" :span="24">
                            <a-form-item label="启动环节" class="index-form-item">
                                {{define.startSection.name}}
                            </a-form-item>
                        </a-col>
                        <template v-if="edit&&linkOptions&&linkOptions.length>0">
                        <a-col :span="24">
                            <a-form-item label="下一步" class="index-form-item">
                                <a-radio-group :options="linkOptions" v-model:value="selected.selectLink" @change="selectNextHandler(true)" />
                            </a-form-item>
                        </a-col>
                        <a-col v-if="instance.currentSection.oid&&instance.currentSection.forwardable=='Y'&&(!selected.selectLink.oid)" :span="24">
                            <a-form-item label="转发给" class="index-form-item">
                                <a-button type="primary" size="small" @click="selectOneAdmin(selected,'adminList',getForwardOrgId(),getForwardRoleId())">选择</a-button>
                                <a-tag style="margin:3px 0 3px 6px;" v-for="admin in selected.adminList" color="processing">{{admin.realname}}</a-tag>
                            </a-form-item>
                        </a-col>
                        <a-col v-else :span="24">
                            <a-form-item label="意见" class="index-form-item">
                                <a-textarea v-model:value="selected.opinion" placeholder="请填写处理意见" auto-size/>
                            </a-form-item>
                        </a-col>
                        </template>
                        <template v-if="edit&&selected.selectLink.isNext=='Y'">
                            <a-col v-if="selected.selectLink.toOption=='OU'" :span="24">
                                <a-form-item label="单选执行人" class="index-form-item">
                                    <a-button v-if="selected.selectable" size="small" type="primary" @click="selectOneAdmin(selected,'adminList',getToOrgId(),getToRoleId())">选择</a-button>
                                    <a-tag style="margin:3px 0 3px 6px;" v-for="admin in selected.adminList" color="processing">{{admin.realname}}</a-tag>
                                </a-form-item>
                            </a-col>
                            <a-col v-if="selected.selectLink.toOption=='MU'" :span="24">
                                <a-form-item label="多选执行人" class="index-form-item">
                                    <a-button v-if="selected.selectable" size="small" type="primary" @click="selectManyAdmin(selected,'adminList',getToOrgId(),getToRoleId())">选择</a-button>
                                    <a-tag style="margin:3px 0 3px 6px;" v-for="admin in selected.adminList" color="processing">{{admin.realname}}</a-tag>
                                </a-form-item>
                            </a-col>
                        </template>
                        <a-col v-if="edit&&selected.selectLink.isNext=='B'" :span="24">
                            <a-form-item label="退回给" class="index-form-item">
                                <a-tag style="margin:3px 0 3px 6px;" color="processing">{{business.applyUser.realname}}</a-tag>
                            </a-form-item>
                        </a-col>
                    </a-row>
                </a-form>
            </a-card>
        </div>
        <a-page-header v-if="instanceSectionList&&instanceSectionList.length>0" title="流程执行情况" style="padding-top:0;">
            <template #extra>
                <a-button v-if="loadOver&&instance.oid" @click="viewFlow();">流程图</a-button>
            </template>
            <a-card :hoverable="true" :bodyStyle="{padding:0}">
                <a-table :data-source="instanceSectionList" size="small" :pagination="false">
                    <a-table-column key="flowIndex" title="" width="50" align="center" data-index="flowIndex"></a-table-column>
                    <a-table-column key="flowSection.name" title="环节" :data-index="['flowSection','name']"></a-table-column>
                    <a-table-column key="user.realname" title="执行人" :data-index="['user','realname']"></a-table-column>
                    <a-table-column key="toDesc" title="结果" data-index="toDesc"></a-table-column>
                    <a-table-column key="remark" title="执行时间">
                        <template #default="{ record,index }">
                            {{new Date(record.acceptDate).formatShow('yyyy-MM-dd HH:mm')}} - {{new Date(record.doneDate).formatShow('yyyy-MM-dd HH:mm')}}
                        </template>
                    </a-table-column>
                    <a-table-column key="opinion" title="意见" data-index="opinion">
                        <template #default="{ text,record,index }">
                            <a-tooltip :title="text">
                            {{text&&text.length>16?(text.substring(0,16)+'...'):text}}
                            </a-tooltip>
                        </template>
                    </a-table-column>
                </a-table>
            </a-card>
        </a-page-header>
    </div>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
		    tabIndex:'1',
			loadOver:false,
			isOpen:false,
			edit:false,
			orgGroup:'',
			roleGroup:'',
			business:{},
			instance:{currentSection:{}},
			define:{startSection:{}},
			instanceSection:{},
			sectionLinks:[],
			instanceSectionList:[],
			linkOptions:[],
			selected:{
				instance:{},
				selectLink:{oid:''},
				opinion:'',
				adminList:[],
				selectable:false,
				flowModel:{}
			},
			dataPv:null//业务page
			//getFlowModel 需实现，返回业务数据
			//flowNextHandler 可实现，流程页面选择活动时触发
		};
	},
	mounted(){
	//this.param: {isOpen:false,business:{oid:'业务主键'}}
		this.isOpen=this.param.isOpen||false;
		this.edit=this.param.edit||false;
		this.business=this.param.business;
		this.initInfo();
	},
	methods:{
		initInfo:function(){
		    this.initDict('manage.model.AdminLogin');
			this.selected.adminList=[];
			this.selected.selectLink={oid:''};
			this.linkOptions=[];
			this.loadFlow(this.loadData);
		},
		loadData:function(){
		    let saveable=this.instanceSection.flowSection.saveable;
			this.loadPage("flowData"+this.key,
				"action/flow/flow/redirectPage",
				{business:this.business,edit:this.edit&&null!=saveable&&saveable=='Y'},
				function(pv,v3){
				    this.loadOver=true;
					this.dataPv=pv;
		        }.bind(this)
	        );
		},
		loadFlow:function(fn){
			this.requestData('action/flow/flow/getFlowInfo',{business:this.business},function(data){
				if(data.code==0){
					this.business=data.business;
					this.instance=data.instance;
					this.instance.business=data.business;
					this.selected.instance=data.instance;
                    this.orgGroup=this.business.toOrg;
                    this.roleGroup=this.business.toRole;
					this.define=data.define;
					this.instanceSection=data.instanceSection;
					this.sectionLinks=data.sectionLinks;
					this.instanceSectionList=data.instanceSectionList;
					if(this.sectionLinks){
					    let endLink=null; let backLink=null;
						for(var i=0;i<this.sectionLinks.length;i++){
							var link=this.sectionLinks[i];
							var to=link.toSection.oid?('('+link.toSection.name+')'):'';
							if(link.isNext=='B'){
							    backLink={label:link.toDesc+to,value:link};
							    continue;
							}else if(link.isNext=='N'){
							    to='(结束)';
							    endLink={label:link.toDesc+to,value:link};
							    continue;
							}
                            this.linkOptions.push({label:link.toDesc+to,value:link});
						}
						if(null!=endLink) this.linkOptions.push(endLink);
						if(null!=backLink) this.linkOptions.push(backLink);
						if(this.sectionLinks&&this.linkOptions.length>0){
							if(this.instance.currentSection.forwardable=='Y'){
								this.linkOptions.push({label:"转发",value:{forwardable:'Y'}});
							}
							this.selected.selectLink=this.linkOptions[0].value;
						}
					}
					if(this.sectionLinks&&!this.sectionLinks.length&&this.edit){
					    this.edit=true;
					}
					this.selectNextHandler(false);
				}else{
					this.remind().error(data.msg);
					if(this.isOpen) this.back(false);
				}
				if(fn) fn();
			}.bind(this));
		},
		selectNextHandler:function(flag){
		    this.selected.adminList=[];
            let user=this.business.nextDefaultUser;
		    if(this.selected.selectLink.isNext=='Y'&&user&&user.length>0){
		        if(this.selected.selectLink.toOption=='OU'){
                    if(user[0]) this.selected.adminList.push({oid:user[0],realname:this.dict('manage.model.AdminLogin',user[0])});
		        }else if(this.selected.selectLink.toOption=='MU'){
                    for(let i=0;i<this.business.nextDefaultUser.length;i++){
                        let u=this.business.nextDefaultUser[i];
                        this.selected.adminList.push({oid:u,realname:this.dict('manage.model.AdminLogin',u)});
                    }
		        }
		    }
            this.selected.selectable=this.business.nextSelectUser!='N';
            if(this.selected.adminList.length==0&&this.selected.selectable){
                let params={orgGroup:this.getToOrgId(),roleGroup:this.getToRoleId(),page:{index:0,num:1}};
                if(this.selected.selectLink.forwardable=='Y'){
                    params['orgGroup']=this.getForwardOrgId();
                    params['roleGroup']=this.getForwardRoleId();
                }
                this.requestData("action/manage/pageUtil/getAdminLink",params,
                    function(data){
                        if(data.code==0){
                            let u=data.list[0].admin.oid;
                            this.selected.adminList.push({oid:u,realname:this.dict('manage.model.AdminLogin',u)})
                        }
                    }.bind(this)
                )
            }
		    if(flag) this.flowNextChange();
		},
		getToOrgId:function(){
		    let org="";
		    let too=this.business.toOrgOption||this.selected.selectLink.toOrgOption;
		    if(this.orgGroup&&this.orgGroup.length){
		        org=this.orgGroup||"";
		    }else if("Y"==too){
		        org=this.selected.selectLink.toOrg||"";
		    }else if("A"==too){
                org=this.business.applyOrg.oid;
            }else if("B"==too){
                org=this.business.applyOrg.parent.oid;
            }
            return org+"";
		},
		getToRoleId:function(){
		    let role="";
		    if(this.roleGroup&&this.roleGroup.length){
		        role=this.roleGroup||"";
		    }else{
		        role=this.selected.selectLink.toRole||"";
		    }
		    return role+"";
		},
		getForwardOrgId:function(){
		    let org="";
		    let too=this.business.toOrgOption||this.instanceSection.toOrgOption;
		    if(this.orgGroup&&this.orgGroup.length){
		        org=this.orgGroup;
		    }else if("Y"==too){
		        org=this.instanceSection.toOrg;
		    }else if("A"==too){
                org=this.business.applyOrg.oid;
            }else if("B"==too){
                org=this.business.applyOrg.parent.oid;
            }
            return org+"";
		},
		getForwardRoleId:function(){
		    let role="";
		    if(this.roleGroup&&this.roleGroup.length){
		        role=this.roleGroup||"";
		    }else{
		        role=this.instanceSection.toRole||"";
		    }
		    return role+"";
		},
		fillFlowModel:function(){
		    if(null!=this.dataPv){
		        if(this.dataPv.getFlowModel){
                    let fm=this.dataPv.getFlowModel();
                    if(!fm){//返回false 不处理
                    }else if(typeof(fm)=="string"){
                        this.remind().error(fm);
                    }else{
                        this.selected.flowModel=fm;
                        return true;
                    }
		        }else{
                    this.remind().error("审核数据页面未实现getFlowModel()方法");
		        }
		    }
            return false;
		},
		saveFlow:function(){
		    if(!this.fillFlowModel()) return;
            this.requestData('action/flow/flow/doSave',
                this.selected,
                function(data){
                    if(data.code==0){
                        this.back(true,this.selected);
                        this.remind().success(data.msg);
                    }else{
                        this.remind().error(data.msg);
                    }
                }.bind(this)
            );
		},
		processFlow:function(){
		    if(!this.fillFlowModel()) return;
            this.requestData('action/flow/flow/doProcess',
                this.selected,
                function(data){
                    if(data.code==0){
                        this.back(true,this.selected);
                        this.remind().success(data.msg);
                    }else{
                        this.remind().error(data.msg);
                    }
                }.bind(this)
            );
		},
		flowNextChange:function(){
		    if(this.dataPv&&this.dataPv.flowNextHandler){
		        this.dataPv.flowNextHandler(this.getInstance(),this.getNextSection());
		    }
		},
		viewFlow:function(){
          	this.openPage('page/base/flow/viewFlowDefine.js',
      			{defineOid:this.define.oid,instanceOid:this.instance.oid},
      			function(flag,obj){}.bind(this),
		        '800px'
	        );
		},
		//获取流程实例
		getInstance:function(){
		    return this.instance;
		},
		//获取下一步
		getNextLink:function(){
		    return this.selected.selectLink;
		},
		//获取下一环节
		getNextSection:function(){
		    return this.selected.selectLink.toSection||{};
		},
		//强行设置下一步执行人,是否有选人按钮
		setUserList:function(userIds,selectable){
		    if(typeof(userIds)!='object') userIds=[userIds];
		    this.business.nextDefaultUser=userIds;
		    this.business.nextSelectUser=selectable?"Y":"N";
		    this.selectNextHandler(false);
		},
		//设置选择机构范围
		setOrgGroup:function(org){
            this.orgGroup=org;
		},
		//设置选择权限范围
		setRoleGroup:function(role){
		    this.roleGroup=role;
		},
	}
}